package com.example.homework09.service;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.homework09.R;
import com.example.homework09.service.MusicService;


public class StartSerivce extends Fragment {
    public StartSerivce(){
        super(R.layout.startservice);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

//    播放
        Button playMusicButton = getView().findViewById(R.id.playMusicButton);
        playMusicButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), MusicService.class);
                getActivity().startService(intent);
            }
        });

//        暂停
        Button stopMusicButton = getView().findViewById(R.id.stopMusicButton);
        stopMusicButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), MusicService.class);
                getActivity().stopService(intent);
            }
        });

    }
}
